import random
user_dict = {12345678:{'账号类型':1,'姓名':'abc','密码':'123456','地址':'a国a省a市a区a路a街','存款余额':100000,'开户行':'中国农业银行'},
             23456789:{'账号类型':2,'姓名':'sbs','密码':'123456','地址':'a国a省a市a区a路a街','存款余额':100000,'开户行':'中国农业银行'}}
def open(**user_info):
    账号类型 = int(input("帐户类型："))
    if 账号类型 == 1:
        print("金卡")
    elif 账号类型 == 2:
        print("普通卡")
    姓名 = input("姓名：")
    while True:
        密码 = input("密码（必须为6位数字）：")
        if len(密码) == 6:
            break
        print("错误：密码长度必须为6位！")

    地址 = input("地址：")
    存款余额 = int(input("存款余额："))
    开户行 = "中国农业银行"
    if len(user_dict) >= 100:
        print("数据库已满")
        return(3)
    attempts = 0
    while attempts < 1000:
        card = "".join(random.choices("0123456789",k=8))
        if card not in user_dict:
            user_dict[card] = {'账号类型':账号类型,'姓名':姓名,'密码':密码,"地址":地址,'存款余额':存款余额,"开户行":开户行}
            print(user_dict)
            return (1)
            break
        elif card in user_dict:
            attempts += 1
    for card_number in user_dict.keys():
        if card_number == card:
            return(2)
def put_money(card,password):
    if card not in user_dict:
        return(False)
    elif password != user_dict[card]['密码']:
        return(False)
    else:
        print("登录成功")
        user_dict[card]['存款余额'] += int(input("输入金额"))
        print(f"存款成功{user_dict[card]['存款余额']}")
        return(True)
def take_money(card,password):
    if card not in user_dict:
        return(1)
    elif password != user_dict[card]['密码']:
        return(2)
    b = int(input("取款金额"))
    if user_dict[card]['存款余额'] < b:
        return(3)
    else:
        user_dict[card]['存款余额'] -= b
        print("取款成功，存款余额",user_dict[card]['存款余额'])
        return(0)
def zhuanzhang():
    put_id = int(input("转出账号"))
    take_id = int(input("转入账号"))
    if put_id not in user_dict or take_id not in user_dict.keys():
        return(1)
    money = int(input("转入金额"))
    put_password = input("账号密码")
    if put_password != user_dict[put_id]['密码']:
        return(2)
    else:
            while True:
                    if user_dict[put_id]['账号类型'] == 1:
                        if money > 50000:
                            print("最大转账额为5万")
                        elif money > user_dict[put_id]['存款余额']:
                             return(3)
                        elif money <= user_dict[put_id]['存款余额']:
                            user_dict[put_id]['存款余额'] -= money
                            user_dict[take_id]['存款余额'] += money
                            print(user_dict[put_id]['姓名'], f"的余额为{user_dict[put_id]['存款余额']}",
                                   user_dict[take_id]['姓名'], f"的余额为{user_dict[take_id]['存款余额']}")
                            return(0)
                    elif user_dict[put_id]['账号类型'] == 2:
                        if money > 20000:
                            print("最大转账额为2w")
                        elif money > user_dict[put_id]['存款余额']:
                            return(3)
                        elif money <= user_dict[put_id]['存款余额']:
                            user_dict[put_id]['存款余额'] -= money
                            user_dict[take_id]['存款余额'] += money
                            print(user_dict[put_id]['姓名'], f"的余额为{user_dict[put_id]['存款余额']}",
                              user_dict[take_id]['姓名'], f"的余额为{user_dict[take_id]['存款余额']}")
                            return(0)
def select():
    while True:
        card = int(input('输入卡号'))
        if card not in user_dict:
            print("该用户不存在")
        else:
            password = input("输入密码")
            if password != user_dict[card]['密码']:
                print("密码错误")
            else:
                print(f"存在{card}",user_dict[card])
                break
caidan = """
        1.开户,
        2.存钱,
        3.取钱,
        4.转账,
        5.查询,
        6.退出系统,
    """
while True:
    print("=" * 50 + "\n" + "中国农业银行帐户管理系统" + "\n" + "=" * 50 + "\n" + "选项" + "\n" + caidan)
    a = int(input("办理业务："))
    if a == 1:
            open()
    if a == 2:
        while True:
           b= put_money(int(input("输入卡号")),input("密码："))
           if b == False:
              print(b)
           elif b == True:
                print(b)
                break
    if a == 3:
        while True:
            b = take_money(int(input("卡号")),input("密码"))
            if b == 1 or b == 2 or b == 3:
                print(b)
            else:
                print(b)
                break

    if a == 4:
        while True:
            x = zhuanzhang()
            if x == 1 or x == 2 or x == 3:
             print(x)
            else:
                print(x)
                break
    if a == 5:
            select()
    if a == 6:
            exit()














